The "use strict"
directive was introduced in ECMAScript 5 and is used to enable strict mode in
JavaScript. Strict mode helps you write cleaner code by catching common coding mistakes and "unsafe" actions.
Strict mode can be enabled for an entire script or for individual functions:
"use strict";
x = 3.14; // This will cause an error because x is not declared
function myFunction() {
"use strict";
y = 3.14; // This will cause an error because y is not declared
}
with
statements.Here are some examples demonstrating the use of strict mode in JavaScript:
"use strict";
x = 3.14; // Error: x is not defined
function myFunction() {
"use strict";
y = 3.14; // Error: y is not defined
}
delete Object.prototype; // Error in strict mode
For more detailed information, you can check out resources like W3Schools[^1^][1] and MDN Web Docs[^2^][2].